package cn.javass.dp.iterator.example7;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

public class ArrayIteratorImpl implements AggregationIterator {

    private PayModel[] pms = null;

    private int index = 0;

    public ArrayIteratorImpl(SalaryManager salaryManager) {
        this.pms = salaryManager.getPms();
    }


    @Override
    public boolean hasNext() {
        if (pms != null && index < pms.length -1) {
            return true;
        }
        return false;
    }

    @Override
    public Collection next(int num) {
        Collection col = new ArrayList();
        int count = 0;
        while (hasNext() && count< num) {
            col.add(pms[index]);
            count++;
            index++;
        }

        return col;
    }

    @Override
    public boolean hasPrevious() {
        if (pms != null && index >0) {
            return true;
        }
        return false;
    }

    @Override
    public Collection previous(int num) {
        Collection col = new ArrayList();
        int count = 0;
        index = index - num;
        while (hasPrevious() && count< num) {
            col.add(pms[index]);
            count++;
            index++;
        }

        return col;
    }


}
